#pragma once

#include "modal_wnd_base.h"
#include <commdlg.h>

namespace ui_comp {

struct __POSITION {};
typedef __POSITION* POSITION;

class UI_COMPONTENTS_API FileDialogEx : public ModalWndBase
{
public:
	typedef std::function<void(bool, std::vector<std::wstring>)> FileDialogCallback;

	enum FileDialogType
	{
		FDT_None,
		FDT_OpenFile,
		FDT_SaveFile,
		FDT_OpenFolder
	};

	FileDialogEx(void);
	~FileDialogEx(void);

public:
	void SetDefExt(LPCTSTR lpszDefExt);
	void SetFileName(LPCTSTR lpszFileName);
	void SetFlags(DWORD dwFlags);
	void SetFilter(LPCTSTR lpszFilter);
	void SetFilter(nbase::list_map<LPCTSTR,LPCTSTR>& filters);
	void SetMultiSel(bool bMultiSel = true);
	void SetPathSelectMode(bool bPathSelect = true);
	void SetParentWnd(HWND hParentWnd);
	void SetTitle(LPCTSTR lpszTitle);
	void SetFileNameBufferSize(DWORD dwSize);

	void AyncShowOpenFileDlg(FileDialogCallback file_dialog_callback);
	void AyncShowSaveFileDlg(FileDialogCallback file_dialog_callback);
	void AyncShowOpenFolderDlg(FileDialogCallback file_dialog_callback);
	virtual void SyncShowModal() override;
	std::wstring GetFileName();
	/*std::wstring GetPathName();
	std::wstring GetFileExt();
	std::wstring GetFileTitle();
	std::wstring GetFolderPath();*/

	POSITION GetStartPosition();
	std::wstring GetNextPathName(POSITION& pos);

public:
	OPENFILENAME m_stOFN;

private:
	wchar_t m_szDefExt[64];
	wchar_t m_szFilter[MAX_PATH];
	wchar_t * m_lpszFileName = nullptr;
	int m_nFileNameLen = MAX_PATH;

	FileDialogType file_dialog_type_;
	FileDialogCallback file_dialog_callback_;
};

}
